﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinformToolkit.Navigations;
using DotNEToolkit;
using System.Runtime.InteropServices;

namespace WinformToolkitDemo.UserControls
{
    public partial class AppContainerUserControl : UserControl, IContentControl
    {
        private IntPtr hwnd = new IntPtr(0x000F12EC);

        [DllImport("user32")]
        public static extern IntPtr SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);

        [DllImport("user32")]
        public static extern bool UpdateLayeredWindow(IntPtr hWnd, IntPtr hdcDst, IntPtr pptDst, IntPtr psize, IntPtr hdcSrc, IntPtr pptSrc, int crKey, IntPtr pblend, int dwFlags);

        [DllImport("user32")]
        public static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr WParam, IntPtr LParam);

        [DllImport("user32")]
        public static extern bool SetWindowLongPtr(IntPtr hwnd, int nIndex, long dwNewLong);

        [DllImport("user32")]
        public static extern bool SetWindowPos(IntPtr hwnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);

        [DllImport("user32")]
        public static extern bool ShowWindow(IntPtr hwnd, int cmdShow);

        public AppContainerUserControl()
        {
            InitializeComponent();

            applicationContainer1.EmbedProcess("calc.exe");
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            //UpdateLayeredWindow(hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero, 0x00000004);
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //SetWindowLongPtr(hwnd, -16, 0x10000000L | 0x40000000L);
            ShowWindow(hwnd, 5);

            // Put it into this form
            //Win32API.SetParent(hwnd, this.Handle);

            //// Remove border and whatnot
            //Win32API.SetWindowLong(new HandleRef(this, hwnd), Win32API.GWL_STYLE, Win32API.WS_VISIBLE);

            //Move the window to overlay it on this window
            //Win32API.MoveWindow(hwnd, 100, 100, this.Width, this.Height, true);

            //SetWindowPos(hwnd, IntPtr.Zero, 0, 0, this.Width, this.Height, 0x0040);

            //UpdateLayeredWindow(hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPr.Zero, 0, IntPtr.Zero, 0x00000004);
        }
    }
}
